#!/bin/bash

#https://www.rabbitmq.com/getstarted.html

#1、环境配置

yum install ncurses ncurses-base ncurses-devel ncurses-libs ncurses-static ncurses-term ocaml-curses ocaml-curses-devel -y

yum install openssl-devel zlib-devel –y

yum -y install make ncurses-devel gcc gcc-c++ unixODBC unixODBC-devel openssl openssl-devel

#2、下载安装erlang

wget https://erlang.org/download/otp_src_20.3.tar.gz

tar -zxvf otp_src_20.3.tar.gz

chown -R root:root otp_src_20.3

cd otp_src_20.3
./configure --prefix=/opt/erlang --with-ssl -enable-threads -enable-smmp-support -enable-kernel-poll --enable-hipe --without-javac

##安装命令：
make&&make install

##要等10分钟左右。。。。。。。。。。。。

vi /etc/profile
#===============
#ERLANG_HOME=/opt/erlang
#PATH=$ERLANG_HOME/bin:$PATH
#export ERLANG_HOME
#export PATH
#================
source /etc/profile
erl -version

#3、下载安装 rabbitmq
#http://www.rabbitmq.com/changelog.html
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.4/rabbitmq-server-generic-unix-3.7.4.tar.xz

yum -y install xz

#解压rabbitmq
xz -d rabbitmq-server-generic-unix-3.7.4.tar.xz
tar -xvf  rabbitmq-server-generic-unix-3.7.4.tar
cd /opt/rabbitmq_server-3.7.4/
./sbin/rabbitmq-server



#启动命令，该命令ctrl+c后会关闭服务
./sbin/rabbitmq-server
#在后台启动Rabbit
./sbin/rabbitmq-server -detached

./sbin/rabbitmqctl add_user ning NingRabbit_123
./sbin/rabbitmqctl set_user_tags ning administrator
./sbin/rabbitmqctl set_permissions -p / ning ".*" ".*" ".*"

#开启插件管理页面
./sbin/rabbitmq-plugins enable rabbitmq_management
#关闭服务
./sbin/rabbitmqctl stop

#http://192.168.202.10:15672/
#


./sbin/rabbitmqctl status |grep rabbit
./sbin/rabbitmqctl list_users
./sbin/rabbitmqctl list_queues

#下载rabbitmqadmin
#http://192.168.202.10:15672/cli
#上传到sbin 下面，然后chmod 755 rabbitmqadmin
#
./rabbitmqadmin -help

./rabbitmqadmin declare queue name=test  auto_delete=false durable=true

#1.durable: 是否需要持久化, true表示持久化, false为非持久化
#2.auto_delete: 是否自动删除, true表示自动删除, false为非自动删除
#补充：
#如需指定vhost的队列(默认是/) 加上 --vhost

./rabbitmqadmin list queues
./rabbitmqadmin publish routing_key=test payload="hello world"
./rabbitmqadmin list queues
./rabbitmqadmin get queue=test
./rabbitmqadmin list bindings



